package org.eremite.corm.party.relationship;

import org.eremite.corm.BaseArchetype;
import org.eremite.corm.party.PartySignature;

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.Arrays;

@Entity
public class AssignedResponsibility extends BaseArchetype {

    private Date fromDate;
    private Date toDate;

    @OneToMany(cascade = {
            CascadeType.PERSIST,
            CascadeType.MERGE})
    private Set<PartySignature> signatures = new HashSet<PartySignature>();

    @ManyToOne(cascade = {
            CascadeType.PERSIST,
            CascadeType.MERGE})
    private Responsibility responsibility;

    public Date getFromDate() {
        return fromDate;
    }

    public void setFromDate(Date fromDate) {
        this.fromDate = fromDate;
    }

    public Date getToDate() {
        return toDate;
    }

    public void setToDate(Date toDate) {
        this.toDate = toDate;
    }

    public Set<PartySignature> getSignatures() {
        return signatures;
    }

    public void setSignatures(Set<PartySignature> signatures) {
        this.signatures = signatures;
    }

    public Responsibility getResponsibility() {
        return responsibility;
    }

    public void setResponsibility(Responsibility responsibility) {
        this.responsibility = responsibility;
    }

    public void addPartySignature(PartySignature ... partySignatures) {
        getSignatures().addAll(Arrays.asList(partySignatures));
    }

    public void addPartySignature(PartySignature partySignature) {
        getSignatures().add(partySignature);
    }
}
